﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:odc="clr-namespace:Odyssey.Controls"
        xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" xmlns:fx="clr-namespace:Odyssey.Effects"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <odc:TwoLineTextConverter x:Key="twoLineTextConverter" />
    <odc:RoundedCornerConverter x:Key="roundedCornerConverter" />

    <ControlTemplate x:Key="SmallRibbonSplitButtonControlTemplate" TargetType="{x:Type odc:RibbonSplitButton}">
        <Grid Focusable="False">
            <odc:RibbonChrome RenderEnabled="{TemplateBinding IsEnabled}" Focusable="False"
                    MouseOverBackground="{DynamicResource {ComponentResourceKey odc:Skins, HighlightedDropDownBg}}"
                    CornerRadius="{TemplateBinding CornerRadius}" BorderBrush="{TemplateBinding BorderBrush}" VerticalContentAlignment="Stretch"
                    HorizontalContentAlignment="Stretch" MinHeight="24" Foreground="{TemplateBinding Foreground}"
                    RenderMouseOver="{TemplateBinding IsMouseOver}">
                <DockPanel Margin="-2" Focusable="False">
                    <odc:RibbonChrome x:Name="PART_DropDown" Focusable="False" RenderFlat="{TemplateBinding IsFlat}" Background="Transparent"
                            BorderBrush="{TemplateBinding BorderBrush}" RenderPressed="{TemplateBinding IsDropDownPressed}"
                            RenderMouseOver="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" HorizontalAlignment="Left"
                            CornerRadius="{Binding CornerRadius,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource roundedCornerConverter},ConverterParameter=right}"
                            Margin="-1,0,0,0" DockPanel.Dock="Right">
                        <odc:RibbonChrome.Content>
                            <Image x:Name="symbol" Source="{DynamicResource {ComponentResourceKey odc:Skins, DownArrowImage}}" Margin="1,1,0,0"
                                    Stretch="None" Width="10" ClipToBounds="True" />
                        </odc:RibbonChrome.Content>
                    </odc:RibbonChrome>

                    <odc:RibbonChrome x:Name="chrome" RenderFlat="{TemplateBinding IsFlat}" Background="Transparent" Focusable="False"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            CornerRadius="{Binding CornerRadius,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource roundedCornerConverter},ConverterParameter=left}"
                            RenderMouseOver="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" RenderPressed="{TemplateBinding IsPressed}">
                        <odc:RibbonChrome.Content>
                            <DockPanel Margin="0" Focusable="False">
                                <Image x:Name="image"
                                        RenderOptions.BitmapScalingMode="{Binding Path=(odc:ImageRenderOptions.SmallImageScalingMode), RelativeSource={RelativeSource TemplatedParent}}"
                                        RenderOptions.EdgeMode="Aliased" Source="{TemplateBinding SmallImage}" VerticalAlignment="Center"
                                        Margin="2,0,0,0" Width="16" Height="16" DockPanel.Dock="Left" ClipToBounds="True" />
                                <ContentPresenter x:Name="content" Content="{TemplateBinding Content}" VerticalAlignment="Center" Margin="2,0,2,0"
                                        Visibility="Visible" />
                            </DockPanel>
                        </odc:RibbonChrome.Content>
                    </odc:RibbonChrome>

                </DockPanel>
            </odc:RibbonChrome>
            <Popup IsOpen="{Binding IsDropDownPressed, RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                    MaxHeight="{TemplateBinding MaxDropDownHeight}" Placement="Bottom" StaysOpen="True"
                    PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{TemplateBinding PopupAnimation}"
                    AllowsTransparency="True" Name="PART_Popup" Focusable="False">
                <mwt:SystemDropShadowChrome Margin="0,0,5,5" Color="#71000000" Name="Shdw" MinWidth="{TemplateBinding FrameworkElement.ActualWidth}">
                    <Border BorderThickness="1,1,1,1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
                            Width="{TemplateBinding DropDownWidth}" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
                            Name="DropDownBorder">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <ContentPresenter Grid.Row="0" Content="{TemplateBinding DropDownHeader}"
                                    ContentTemplate="{TemplateBinding DropDownHeaderTemplate}" />
                            <Grid Grid.Row="1" SnapsToDevicePixels="True">
                                <Rectangle RadiusX="2" RadiusY="2" Fill="#FFF1F1F1" Width="22" Margin="2,2,2,2" HorizontalAlignment="Left" />
                                <Rectangle Fill="#FFE2E3E3" Width="1" Margin="25,2,0,2" HorizontalAlignment="Left" />
                                <Rectangle Fill="#FFFFFFFF" Width="1" Margin="26,2,0,2" HorizontalAlignment="Left" />
                                <ScrollViewer x:Name="scroller" VerticalScrollBarVisibility="Auto" SnapsToDevicePixels="True"
                                        HorizontalScrollBarVisibility="Disabled" CanContentScroll="True" Margin="2">
                                    <ItemsPresenter x:Name="items" Focusable="False" KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                            </Grid>
                            <ContentPresenter Grid.Row="2" Content="{TemplateBinding DropDownFooter}"
                                    ContentTemplate="{TemplateBinding DropDownFooterTemplate}" />
                        </Grid>
                    </Border>
                </mwt:SystemDropShadowChrome>
                <Popup.Resources>
                    <Style TargetType="{x:Type odc:RibbonButton}">
                        <Setter Property="odc:RibbonBar.Size" Value="Medium" />
                    </Style>
                </Popup.Resources>
            </Popup>
        </Grid>

        <ControlTemplate.Resources>
            <Style TargetType="{x:Type odc:RibbonButton}">
                <Setter Property="odc:RibbonBar.Size" Value="Medium" />
                <Setter Property="Template" Value="{DynamicResource RibbonButtonSmallControlTemplate}" />
            </Style>
        </ControlTemplate.Resources>
        <ControlTemplate.Triggers>
            <Trigger Property="odc:RibbonBar.Size" Value="Small">
                <Setter Property="Visibility" Value="Collapsed" TargetName="content" />
            </Trigger>
            <Trigger Property="odc:RibbonBar.Size" Value="Minimized">
                <Setter Property="Visibility" Value="Collapsed" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsEnabled" Value="False" />
                    <Condition Property="odc:RibbonChrome.IsGrayScaleEnabled" Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="RenderOptions.EdgeMode" Value="Unspecified" TargetName="image" />
                <Setter Property="RenderOptions.BitmapScalingMode" Value="Fant" TargetName="image" />
                <Setter Property="Opacity" Value="{DynamicResource {ComponentResourceKey odc:Skins, DisabledImageOpacity}}" TargetName="image" />
                <Setter Property="Effect" TargetName="image">
                    <Setter.Value>
                        <fx:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </MultiTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource {ComponentResourceKey odc:Skins, DisabledForegroundBrush}}" />
            </Trigger>
            <Trigger Property="IsDropDownPressed" Value="True">
                <!--Don't open the tooltip when the popup is open:-->
                <Setter Property="ToolTip" Value="{x:Null}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="LargeRibbonSplitButtonControlTemplate" TargetType="{x:Type odc:RibbonSplitButton}">
        <odc:RibbonChrome Height="72" RenderEnabled="{TemplateBinding IsEnabled}" Background="{TemplateBinding Background}"
                MouseOverBackground="{DynamicResource {ComponentResourceKey odc:Skins, HighlightedDropDownBg}}"
                CornerRadius="{TemplateBinding CornerRadius}" BorderBrush="{TemplateBinding BorderBrush}" VerticalContentAlignment="Stretch"
                HorizontalContentAlignment="Stretch" RenderMouseOver="{TemplateBinding IsMouseOver}" Focusable="False">
            <Grid Height="72" Margin="-2" Focusable="False">
                <Grid.RowDefinitions>
                    <RowDefinition Height="44" />
                    <RowDefinition Height="28" />
                </Grid.RowDefinitions>

                <odc:RibbonChrome x:Name="PART_DropDown" Focusable="False" Grid.Row="1"
                        MouseOverBackground="{DynamicResource {ComponentResourceKey odc:Skins, HighlightedRadialDropDownBtnBrush}}"
                        RenderPressed="{TemplateBinding IsDropDownPressed}"
                        RenderMouseOver="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
                        MousePressedBackground="{DynamicResource {ComponentResourceKey odc:Skins, HighlightedPressedBtnBrush}}"
                        VerticalAlignment="Stretch" HorizontalContentAlignment="Center"
                        CornerRadius="{Binding CornerRadius,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource roundedCornerConverter},ConverterParameter=bottom}"
                        Margin="0,-1,0,0">

                    <odc:RibbonChrome.Content>
                        <Grid Focusable="False">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="content2" Grid.Row="0"
                                    Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource twoLineTextConverter},ConverterParameter=1}"
                                    VerticalAlignment="Center" HorizontalAlignment="Center" />
                            <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Bottom"
                                    Focusable="False">

                                <TextBlock Grid.Row="1"
                                        Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource twoLineTextConverter},ConverterParameter=2}"
                                        VerticalAlignment="Bottom" HorizontalAlignment="Center" />

                                <Image Source="{DynamicResource {ComponentResourceKey odc:Skins, DownArrowImage}}" Margin="2,0,2,0" Stretch="None" />
                            </StackPanel>
                        </Grid>
                    </odc:RibbonChrome.Content>
                </odc:RibbonChrome>

                <odc:RibbonChrome x:Name="chrome" HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom" Focusable="False"
                        CornerRadius="{Binding CornerRadius,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource roundedCornerConverter},ConverterParameter=top}"
                        RenderMouseOver="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" RenderPressed="{TemplateBinding IsPressed}">
                    <odc:RibbonChrome.Content>
                        <Grid Focusable="False">

                            <DockPanel HorizontalAlignment="Center" Margin="2,4,2,4">
                                <Image x:Name="image"
                                        RenderOptions.BitmapScalingMode="{Binding Path=(odc:ImageRenderOptions.LargeImageScalingMode), RelativeSource={RelativeSource TemplatedParent}}"
                                        RenderOptions.EdgeMode="Aliased" Source="{TemplateBinding LargeImage}" VerticalAlignment="Center"
                                        Margin="2,0,2,0" Width="32" Height="32" DockPanel.Dock="Top" Stretch="UniformToFill" />
                            </DockPanel>

                            <Popup IsOpen="{Binding IsDropDownPressed, RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                                    MaxHeight="{TemplateBinding MaxDropDownHeight}" Placement="Bottom" StaysOpen="True"
                                    PopupAnimation="{TemplateBinding PopupAnimation}"
                                    PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" AllowsTransparency="True"
                                    Name="PART_Popup" Focusable="False">
                                <mwt:SystemDropShadowChrome Margin="0,0,5,5" Color="#71000000" Name="Shdw"
                                        MinWidth="{TemplateBinding FrameworkElement.ActualWidth}">
                                    <Border Width="{TemplateBinding DropDownWidth}" BorderThickness="1,1,1,1"
                                            BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
                                            Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Name="DropDownBorder">
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="*" />
                                                <RowDefinition Height="Auto" />
                                            </Grid.RowDefinitions>
                                            <ContentPresenter Grid.Row="0" Content="{TemplateBinding DropDownHeader}"
                                                    ContentTemplate="{TemplateBinding DropDownHeaderTemplate}" />
                                            <Grid Grid.Row="1" SnapsToDevicePixels="True">
                                                <Rectangle RadiusX="2" RadiusY="2" Fill="#FFF1F1F1" Width="22" Margin="2,2,2,2"
                                                        HorizontalAlignment="Left" />
                                                <Rectangle Fill="#FFE2E3E3" Width="1" Margin="25,2,0,2" HorizontalAlignment="Left" />
                                                <Rectangle Fill="#FFFFFFFF" Width="1" Margin="26,2,0,2" HorizontalAlignment="Left" />
                                                <ScrollViewer x:Name="scroller" VerticalScrollBarVisibility="Auto" SnapsToDevicePixels="True"
                                                        HorizontalScrollBarVisibility="Disabled" CanContentScroll="True" Margin="2">
                                                    <ItemsPresenter x:Name="items" Focusable="False"
                                                            KeyboardNavigation.DirectionalNavigation="Contained" />
                                                </ScrollViewer>
                                                <ContentPresenter Grid.Row="2" Content="{TemplateBinding DropDownFooter}"
                                                        ContentTemplate="{TemplateBinding DropDownFooterTemplate}" />
                                            </Grid>
                                        </Grid>
                                    </Border>
                                </mwt:SystemDropShadowChrome>
                            </Popup>

                        </Grid>
                    </odc:RibbonChrome.Content>
                </odc:RibbonChrome>
            </Grid>
        </odc:RibbonChrome>
        <ControlTemplate.Triggers>
            <Trigger Property="IsOpen" Value="True" SourceName="PART_Popup">
                <Setter Property="RenderMouseOver" Value="true" TargetName="chrome" />
            </Trigger>
            <Trigger Property="odc:RibbonBar.Size" Value="Minimized">
                <Setter Property="Visibility" Value="Collapsed" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsEnabled" Value="False" />
                    <Condition Property="odc:RibbonChrome.IsGrayScaleEnabled" Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="RenderOptions.EdgeMode" Value="Unspecified" TargetName="image" />
                <Setter Property="RenderOptions.BitmapScalingMode" Value="Fant" TargetName="image" />
                <Setter Property="Opacity" Value="{DynamicResource {ComponentResourceKey odc:Skins, DisabledImageOpacity}}" TargetName="image" />
                <Setter Property="Effect" TargetName="image">
                    <Setter.Value>
                        <fx:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </MultiTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource {ComponentResourceKey odc:Skins, DisabledForegroundBrush}}" />
            </Trigger>
            <Trigger Property="IsDropDownPressed" Value="True">
                <!--Don't open the tooltip when the popup is open:-->
                <Setter Property="ToolTip" Value="{x:Null}" />
            </Trigger>
        </ControlTemplate.Triggers>
        <ControlTemplate.Resources>
            <Style TargetType="{x:Type odc:RibbonButton}">
                <Setter Property="odc:RibbonBar.Size" Value="Medium" />
                <Setter Property="Template" Value="{DynamicResource RibbonButtonSmallControlTemplate}" />
            </Style>
        </ControlTemplate.Resources>

    </ControlTemplate>

    <Style TargetType="{x:Type odc:RibbonSplitButton}">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey odc:Skins, HighlightedRibbonBorderBrush}}" />
        <Setter Property="odc:RibbonChrome.AnimateTransition"
                Value="{Binding Path=(odc:RibbonOption.AnimateTransition), RelativeSource={RelativeSource Self}}" />
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template" Value="{StaticResource SmallRibbonSplitButtonControlTemplate}" />
        <Style.Triggers>
            <Trigger Property="odc:RibbonBar.Size" Value="Large">
                <Setter Property="Template" Value="{StaticResource LargeRibbonSplitButtonControlTemplate}" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>